<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
    <script src="../js/jquery-1.11.3.min.js"></script>
</head>
<body>
<p>hello,登陆成功</p>
<button onclick="update()">测试update权限</button>
<button onclick="add()">测试add权限</button>
<button onclick="window.location.href='/logout'">退出登录</button>
</body>
<script>
    function logout() {
        $.post("/logout", "", function (res) {
            alert("logout");
            console.log(res);
        })
    };

    function update() {
        $.ajax({
            type: "GET",
            url: "/update",
            data: {},
            dataType: "json",
            success: function (data) {
                console.log("data===" + data);
                alert("code="+data.code+"msg="+data.msg);
                // if (isJSON(data)) {
                //     console.log("是json==" + data)
                // } else {
                //     console.log("不是json")
                //     var d = JSON.stringify(data);
                //     console.log(d);
                //     var d2 = JSON.parse(d);
                //     console.log(d2);
                // }
            },
            error: function (data) {
                console.log("error" + data);
                console.log(data.responseJSON);
            }
        });
    };

    function isJSON(str) {
        if (typeof str == 'string') {
            try {
                JSON.parse(str);
                return true;
            } catch (e) {
                console.log(e);
                return false;
            }
        }
        console.log('It is not a string!')
    }

    function add() {
        $.get("/add", "", function (res) {
            console.log(res);
        })
    };

</script>
</html>